package com.touni.designpattern.compositepattern;

import java.util.Iterator;

/**
 * @ClassName : CompositeDemo
 * @Description : 组合模式
 * 部分整体模式，是用于把一组相似的对象当作一个单一的对象。组合模式依据树形结构来组合对象，用来表示部分以及整体层次。
 * 这种类型的设计模式属于结构型模式，它创建了对象组的树形结构。
 * @Author : lwq
 * @Date: 2020-11-12 09:02
 */
public class CompositeDemo {
    public static void main(String[] args) {
        Employee chief = new Employee("touni","chief",10000000);
        Employee market = new Employee("lisa","market",5000);
        chief.addList(market);
        Employee sale1 = new Employee("mike","market",6000);
        Employee sale2 = new Employee("tt","market",6000);
        market.addList(sale1);
        market.addList(sale2);
        System.out.println(chief);
        System.out.println("=======================================");
        Iterator<Employee> iterator = chief.getEmployeeList().iterator();
        while (iterator.hasNext()){
            Employee next = iterator.next();
            System.out.println(next);
            Iterator<Employee> iterator1 = next.getEmployeeList().iterator();
            while (iterator1.hasNext()){
                System.out.println(iterator1.next());
            }
        }
    }
}
